//
//  ViewController.m
//  tucici
//
//  Created by SKL on 2017/11/28.
//  Copyright © 2017年 SKL. All rights reserved.
//

#import "ViewController.h"
#import <XOWMSDK/XOWMSDK.h>
@interface ViewController ()<XOWMPlatformDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self img];
    [self addBtn];
    UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(300, 300, 300, 60)];
     textfield.backgroundColor = [UIColor whiteColor];
     textfield.layer.borderColor = [UIColor redColor].CGColor;
     textfield.layer.borderWidth = 1.0;
     textfield.borderStyle = UITextBorderStyleRoundedRect;
     textfield.layer.masksToBounds = YES;
     textfield.layer.cornerRadius = 5;
     [self.view addSubview:textfield];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)img
{
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    img.image = [UIImage imageNamed:@"beijing.jpg"];
    [self.view addSubview:img];
}

- (void)addBtn
{
    NSArray *titles = @[@"登陆",@"注册",@"支付",@"结束支付"];
    CGFloat x = 20;
    CGFloat H = 44;
    CGFloat W = 100;
    for (int i = 0; i < titles.count; i++)
    {
        NSString *title = titles[i];
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(x, 100 + (x + H) * i, W, H)];
        [button addTarget:self action:@selector(actionForBtn:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor whiteColor]];
        [button setTitle:title forState:UIControlStateNormal];
        button.layer.cornerRadius = 5;
        button.layer.borderColor = [UIColor lightGrayColor].CGColor;
        button.layer.borderWidth = 0.5;
        button.layer.masksToBounds = YES;
        button.tag = 200 + i;
        [self.view addSubview:button];
    }
}

#pragma mark - XOWMPlatformDelegate 方法
- (void)receiveCallBack:(NSDictionary *)callback
{
    /*登录和支付都走这个回调，
     1.登录回调，callback有值，返回相应参数
     2.支付回调，callback为nil，表示支付动作完成
     */
    NSLog(@"dict %@ \n",callback);
    NSString *account = [[XOWMPlatform platform] account];
    NSString *accountid = [[XOWMPlatform platform] accountID];
    NSString *token =[[XOWMPlatform platform] token];
    NSLog(@"name %@  id %@  token %@",account, accountid, token);
}


- (void)actionForBtn:(UIButton *)sender
{
    //设置代理
    XOWMPlatform *SKL = [XOWMPlatform platform];
    SKL.delegate = self;
    
    if (sender.tag == 200)
    {
        //登录
        [XOWMPlatform prepareLogin];
    }
    else if (sender.tag == 201)
    {
        //注册
        [XOWMPlatform prepareRegister];
    }
    else if(sender.tag == 202){
        //支付
        XOWMProduct *product = [[XOWMProduct alloc]init];
//        product.goodsID = @"com.jzsm.68zzk";//内购商品ID ---- 必传
        product.goodsID = @"com.yjd.ydnz.6y";//内购商品ID ---- 必传
        product.goodsTitle = @"测试商品标题";//内购商品名称 ---- 必传
        product.goodsPrice = @"0.01";//内购商品价格 ---- 必传
        product.serverID = @"0000";//游戏区服ID ---- 必传
        product.serverName = @"测试-天下第一区";//游戏区服名称 ---- 必传
        product.roleID = @"1002";//游戏角色ID ---- 必传
        product.roleName = @"测试角色名称";//游戏角色名称 ---- 必传
        product.roleLevel= @"10";
        product.notifyURL = @"http://101.200.125.112/api/gameserver/gamecallback.php";//游戏后台接收支付通知接口回调 ---- 必传
        [XOWMPlatform zunbeizhifu:product];
    }
    else
    {
//        [XOWMPlatform cancelzhifu];
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"进入viewcontroller");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
@end
